package com.javastudy.liuhouse.xml_json.json;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.math.BigInteger;

public class IsbnDeserializer extends JsonDeserializer<BigInteger> {
    @Override
    public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
        //读取原始的JSON字符串内容
        String s = p.getValueAsString();
        if(s != null){
            try{
                return new BigInteger(s.replace("-" , ""));
            }catch (NumberFormatException e){
                throw new JsonParseException(p, s , e);
            }
        }
        return null;
    }
}
